<template>
  <div class="app-container">
    <el-form :model="form" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="状态">
        <!-- <el-input
            v-model="form.nickName"
            placeholder="请输入昵称"
            clearable
            size="small"
          /> -->
        <el-radio-group v-model="form.status" size="medium">
          <el-radio-button
            v-for="item in TypeList"
            :key="item.id"
            :label="item.value"
            >{{ item.name }}</el-radio-button
          >
        </el-radio-group>
      </el-form-item>
      <!--  -->
      <br />
      <el-form-item label="订单编号">
        <el-input
          v-model="form.goodsNo"
          placeholder="请输入订单编号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getList()"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table :data="list">
      <el-table-column label="ID" width="150" align="center" prop="id" />
      <el-table-column
        label="订单编号"
        width="150"
        align="center"
        prop="goodsNo"
      />
      <el-table-column
        label="商品类型"
        width="126"
        align="center"
        prop="goodsCatalogueName"
      />
      <el-table-column
        width="266px"
        label="游戏名称/区服"
        align="center"
        prop="simpleMessage"
      />
      <el-table-column
        label="账号标题"
        width="333px"
        align="center"
        prop="product_name"
      >
        <template #default="{ row }">
          <div style="height: 88px">{{ row.title }}</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" width="100px">
        <template #default="{ row }">
          <div style="color: red" v-if="row.status == 'BUYER_QUOTATION'">
            待处理
          </div>
          <div style="color: red" v-if="row.status == 'BUYER_QUOTATION_AGAIN'">
            二次出价
          </div>
          <div style="color: red" v-if="row.status == 'SELLER_COUNTER_OFFER'">
            已还价
          </div>
          <div style="color: red" v-if="row.status == 'SELLER_AGREE'">
            已同意
          </div>
          <div style="color: red" v-if="row.status == 'BUYER_AGREE'">
            买家同意
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="原价"
        width="150px"
        align="center"
        prop="goodsPrice"
      />
      <el-table-column
        label="买家报价"
        width="150px"
        align="center"
        prop="bargainPrice"
      />
      <el-table-column
        label="还价"
        width="150px"
        align="center"
        prop="sellPrice"
      >
        <template #default="{ row }">
          <div>{{ row.sellerPrice ? row.sellerPrice : 0 }}</div>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="交易状态"
        width="150px"
        align="center"
        prop="pay_status"
      /> -->
      <el-table-column
        label="报价时间"
        width="266px"
        align="center"
        prop="cancelableTime"
      />
      <el-table-column
        label="操作"
        v-if="form.status == 'BUYER_QUOTATION'"
        fixed="right"
        width="188"
        align="center"
      >
        <template #default="{ row }">
          <el-button type="text" @click="huanjia(row)">还价</el-button>
          <el-button type="text" @click="tongyi(row)">同意</el-button>
          <el-button type="text" @click="jujue(row)">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div style="text-align: right; margin-top: 20px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="form.page"
        :page-sizes="[10, 20, 30, 60]"
        :page-size="form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
    
    <script>
import reportRecordApi from '@/api/CraBbargaining/panzhi'
export default {
  data() {
    return {
      form: {
        page: 1,
        pageSize: 10,
        status: 'BUYER_QUOTATION',
        goodsNo: null
      },
      TypeList: [
        { name: '待处理', id: 1, value: 'BUYER_QUOTATION' },
        { name: '二次出价', id: 2, value: 'BUYER_QUOTATION_AGAIN' },
        { name: '已还价', id: 3, value: 'SELLER_COUNTER_OFFER' },
        { name: '已同意', id: 4, value: 'SELLER_AGREE' },
        { name: '买家同意', id: 5, value: 'BUYER_AGREE' }
      ],
      list: [],
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      const res = await reportRecordApi.getList(this.form)
      console.log('res', res);
      this.list = res.data.records
      this.total = res.data.total
    },
    resetQuery() {
      this.form = {
        page: 1,
        pageSize: 10,
        status: 'BUYER_QUOTATION',
        keyword: null,
        gameAccount: null
      }
      this.getList()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.form.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.form.page = val
      this.getList()
    },
    huanjia(item) {
      this.$prompt('请输入价格！', '温馨提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /\S+/,
        inputErrorMessage: '请输入价格'
      }).then(({ value }) => {
        let obj = {}
        obj.id = item.id
        obj.sellerPrice = value
        reportRecordApi.huanjiainfo(obj).then(res => {
          if (res.code == 200) {
            this.flag = true
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.getList()
          } else {
            this.$message({
              type: "error",
              message: "操作失败!"
            });
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    },
    tongyi(item) {
      this.$confirm('此操作将同意还价, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let obj = {}
        obj.id = item.id
        obj.agreeStatus = "SELLER_AGREE"
        reportRecordApi.againInfo(obj)
        this.getList()
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    jujue(item) {
      this.$confirm('此操作将拒绝还价, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let obj = {}
        obj.id = item.id
        obj.agreeStatus = "SELLER_REFUSE"
        reportRecordApi.againInfo(obj)
        this.getList()
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
  }
}
    </script>
    
    <style>
</style>